docker-compose up -d

echo "Gitlab is starting ..."
echo "You can access the site (http://127.0.0.1) after 5 minutes ."


# 更改 Gitlab Pages 的 nginx 代理服务为 127.0.0.1:8000
sleep 300
$DOCKER_ID = (docker ps -aq --filter name=docker_gitlab)
if(![String]::IsNullOrEmpty($DOCKER_ID)) {
    docker exec -u root ${DOCKER_ID} /bin/bash -c "cp /var/opt/gitlab/nginx/conf/gitlab-pages.conf.bak /var/opt/gitlab/nginx/conf/gitlab-pages.conf"
    docker exec -u root ${DOCKER_ID} /bin/bash -c "sed -i 's/listen.*/listen 8000;/g;s/server_name.*/server_name 127.0.0.1;/g' /var/opt/gitlab/nginx/conf/gitlab-pages.conf"
    docker exec -u root ${DOCKER_ID} /bin/bash -c "sed -i '31,49d' /var/opt/gitlab/nginx/conf/gitlab-pages.conf"
    docker exec -u root ${DOCKER_ID} /bin/bash -c "sed -i 'N;30a\ \ \ \ index index.html;' /var/opt/gitlab/nginx/conf/gitlab-pages.conf"
    docker exec -u root ${DOCKER_ID} /bin/bash -c "sed -i 'N;30a\ \ \ \ root /var/opt/gitlab/gitlab-rails/shared/pages;' /var/opt/gitlab/nginx/conf/gitlab-pages.conf"
    docker exec -u root ${DOCKER_ID} /bin/bash -c "gitlab-ctl restart nginx"
}

echo "Gitlab is started ."
exit 0
